﻿using System;
using System.Linq;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using Newtonsoft.Json.Linq;

namespace FFWinMobile
{
    public partial class frmFeed : Form
    {
        string to = "";
        public frmFeed()
        {
            InitializeComponent();
        }
        public frmFeed(string recipients)
        {
            to = recipients;
            InitializeComponent();
        }

        private void textBox1_TextChanged(object sender, EventArgs e)
        {

        }

        private void menuItem3_Click(object sender, EventArgs e)
        {
            this.Close();
        }

        private void miRefresh_Click(object sender, EventArgs e)
        {
            txtFeed.Text = "";
        }

        private void miMe_Click(object sender, EventArgs e)
        {
            frmUserForm frm = new frmUserForm("me");
            frm.Show();
            this.Close();

        }

        private void btnSend_Click(object sender, EventArgs e)
        {
            if (!string.IsNullOrEmpty(txtFeed.Text))
            {
                string response;
                
                    response = FF.FeedCreate(txtFeed.Text,to);
                
                if (response != "error")
                {
                    this.DialogResult = DialogResult.OK;
                    this.Close();
                }
                else
                {
                    MessageBox.Show(Properties.Resources.ERROR_OCCURED);
                }
            }
        
        }

        private void miSettings_Click(object sender, EventArgs e)
        {
            frmAbout frm = new frmAbout();
            frm.Show();
        }

        private void miSettings_Click_1(object sender, EventArgs e)
        {
            frmSettings frm = new frmSettings();
            frm.ShowDialog();
        }

        private void frmFeed_Load(object sender, EventArgs e)
        {

            if (!string.IsNullOrEmpty(to))
            {
                int x = 3, y = 3;
                string user = FF.ReadUserFeed(to, 0);
                JObject j = JObject.Parse(user);
                string userName = j["name"].Value<string>();
                Label lbl = new Label();
                lbl.Text = string.Format(Properties.Resources.TO, userName);
                lbl.Height = CFMeasureString.MeasureString(lbl, lbl.Text, this.ClientRectangle).Height;
                lbl.Width = (this.ClientRectangle.Width - 10);
                lbl.Location = new Point(x, y);
                this.Controls.Add(lbl);
                y += (lbl.Height + 2);

                txtFeed.Height -= y;
                txtFeed.Location = new Point(x, y);
                

            }
        }
    }
}